package com.luca.web.controller.system;

import com.luca.common.annotation.Log;
import com.luca.common.core.controller.BaseController;
import com.luca.common.core.domain.JsonResult;
import com.luca.common.enums.BusinessType;
import com.luca.common.utils.poi.ExcelUtil;
import com.luca.system.domain.WechatInfo;
import com.luca.system.service.IWechatInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.luca.common.core.page.TableDataInfo;

/**
 * 微信公众号信息Controller
 * 
 * @author luca
 * @date 2021-03-26
 */
@RestController
@RequestMapping("/system/wechat-info")
public class WechatInfoController extends BaseController {

    @Autowired
    private IWechatInfoService wechatInfoService;

    /**
     * 查询微信公众号信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:list')")
    @GetMapping("/list")
    public TableDataInfo list(WechatInfo wechatInfo) {
        startPage();
        List<WechatInfo> list = wechatInfoService.selectWechatInfoList(wechatInfo);
        return getDataTable(list);
    }

    /**
     * 导出微信公众号信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:export')")
    @Log(title = "微信公众号信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public JsonResult export(WechatInfo wechatInfo) {
        List<WechatInfo> list = wechatInfoService.selectWechatInfoList(wechatInfo);
        ExcelUtil<WechatInfo> util = new ExcelUtil<WechatInfo>(WechatInfo.class);
        return util.exportExcel(list, "info");
    }

    /**
     * 获取微信公众号信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:query')")
    @GetMapping
    public JsonResult getInfo() {
        return JsonResult.success(wechatInfoService.selectWechatInfoByTenantId());
    }

    /**
     * 新增微信公众号信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:add')")
    @Log(title = "微信公众号信息", businessType = BusinessType.INSERT)
    @PostMapping
    public JsonResult add(@RequestBody WechatInfo wechatInfo) {
        wechatInfoService.insertWechatInfo(wechatInfo);
        return JsonResult.success();
    }

    /**
     * 修改微信公众号信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:edit')")
    @Log(title = "微信公众号信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public JsonResult edit(@RequestBody WechatInfo wechatInfo) {
        wechatInfoService.updateWechatInfo(wechatInfo);
        return JsonResult.success();
    }

    /**
     * 删除微信公众号信息
     */
    @PreAuthorize("@ss.hasPermi('system:wechat-info:remove')")
    @Log(title = "微信公众号信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public JsonResult remove(@PathVariable Long[] ids) {
        wechatInfoService.deleteWechatInfoByIds(ids);
        return JsonResult.success();
    }

}
